<?php

// Error reporting:
error_reporting(E_ALL^E_NOTICE);

// Including the DB connection file:

require_once("../functions/session.php");
require_once("../functions/connect_to_database.php");

$project_name = $_POST['prname'];
$username = $_POST['username'];


$query = mysql_query("SELECT * FROM `$project_name` ORDER BY id DESC");
$notes = '';
$left='';
$top='';
$zindex='';

if(!$query)
		die(mysql_error());

while($row=mysql_fetch_assoc($query))
{
	// The xyz column holds the position and z-index in the form 200x100x10:
	list($left,$top,$zindex) = explode('x',$row['xyz']);

	$notes.= '
	<div class="note '.$row['color'].'" style="left:'.$left.'px;top:'.$top.'px;z-index:'.$zindex.'">
		<div class="author">'.htmlspecialchars($row['name']).'</div>
		<div style="width:100%; height:16px"></div>
		'.htmlspecialchars($row['text']).'
		<span class="data">'.$row['id'].'</span>
	</div>';
}

//find out whether the user is a chicken in this project or not
$query = sprintf("select isChicken from projects where name='%s' and participant='%s'", $project_name, $_SESSION['usr']);
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$chicken = $row['isChicken'] == "1" ? true : false;


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $project_name ?></title>
<script>
	$("body").removeClass("imageBg");
</script>
<script>
		var username = '<?php echo $_SESSION["usr"];?>'; 
		var project_name = '<?php echo $project_name;?>';
</script>

<script type="text/javascript"> 
 
		jQuery(document).ready(function(){
			$('#fname').autocomplete({source:'functions/autocomplete.php', minLength:1});
		});
 
</script> 

<script type="text/javascript">
$(document).ready(function(){
	$("form#submit").submit(function() {
		// we want to store the values from the form input box, then send via ajax below
		var fname = $('#fname').attr('value');
		var project_name = '<?php echo $project_name;?>';
		var chicken = $('#chicken_check').is(':checked') ? "true" : "false";
		$.post('functions/add_participants.php',{'pname' : project_name,'fname':fname, 'chicken':chicken},function(data){
			if(data.indexOf("User") == 0)
				alert(data);
			else{
				$("#users").html(data);
				$('#fname').val("");
				$("#chicken_check").removeAttr('checked');
			}
		});
			
		return false;
	});
});

</script>

<!--<script type="text/javascript">
// Check if the user has been active, i.e. mouse movement, mouse click, keystrocks, mouse wheel action.   
    (function($){
      
        var timeout = 15000;
        var username = '?php echo $username;?>';

        $(document).bind("idle.idleTimer", function(){
        	$.post("functions/logout.php", {"username":username}, function(){
    			window.location = "index.php";
    		});
        });
        
        $.idleTimer(timeout);
    
    
   })(jQuery);
    
</script>


--></head>

<body>

<h1 id="project_name"><font face="Georgia"><?php echo $project_name?></font></h1>

<!--<h2  onclick="showProjectTab();"><a>Open in new tab</a></h2> @TODO-->

<!--  Used for filling with participant names -->
<div class="users_list">
	<div id="users"></div>
</div>


<?php if(!$chicken){ ?>	
<div id="add_users">
	<form id="submit" method="post">
	<label for="fname"><font face="Georgia">Username:</font></label>
	<br/> 	
	<input style="color: #000000; font-family:Georgia; background-color: #EEEEEE" id="fname" class="text" type="text" name="fname" size="13" /> 
	<button class="button positive" value="Add Participant" style="color:yellow; background-color: red"><font face="Georgia" weight="bold"><b>+<b/></font></button><br>
	<input type="checkbox" id="chicken_check" name="chicken" value="chicken"  /> chicken
	</form>
</div>
<?php }else{ ?>	
	<div id="chicken">
		<img src="images/chicken.png" width="100px" height="100px" />
	</div>
<?php } ?>	

<!-- Div for displaying the chat window -->
<div class="sideBar" id="chat"> 
	<div id="chatText"></div>
<?php if(!$chicken){ ?>	
	<p><font weight="normal">Type Message Here:</font></p>
	<input type="text" id="chatBar" value"Type message here"/>
<?php } ?>	
</div>

<script src="js/project.js" type="text/javascript" ></script>

<div id="main">
<?php if(!$chicken){ ?>	
	<a id="addButton" class="green-button" href="ajax/story_form.html" accesskey="s">New Story</a>

	<!--Export the project db table to a .csv file--> 
	<?php echo "<a id='exportButton' class='green-button' href='functions/export_to_csv.php?project_name=".$project_name."'accesskey='z'>Export</a>"; ?>
	
<?php } ?>	
	
	<div id="one_point_main" class="droppable point_div">
		<div id="one_points_points">
			<?php if(!$chicken){ ?>
			<select id="one">
				<option value="">Size</option>
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3" style="color:green">3</option>
				<option value="4" style="color:red">4</option>
				<option value="5" style="color:green">5</option>
				<option value="8">8</option>
				<option value="13" style="color:green">13</option>
				<option value="16" style="color:red">16</option>
				<option value="20+" style="color:green">20+</option>
				<option value="32+" style="color:red">32+</option>
			</select> 
			<?php } ?>
			<span id="one_point_display">Size: <span class="one_size"></span></span> 
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<span id="one_point_div_count"><span class="one_kids"></span></span>
		</div>
	</div>
	
	<div id="two_points_main" class="droppable point_div">
		<div id="two_points_points">
			<?php if(!$chicken){ ?>
			<select id="two">
				<option value="">Size</option>
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3" style="color:green">3</option>
				<option value="4" style="color:red">4</option>
				<option value="5" style="color:green">5</option>
				<option value="8">8</option>
				<option value="13" style="color:green">13</option>
				<option value="16" style="color:red">16</option>
				<option value="20+" style="color:green">20+</option>
				<option value="32+" style="color:red">32+</option>
			</select> 
			<?php } ?>
			<span id="two_points_display">Size: <span class="two_size"></span></span>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<span id="two_points_div_count"><span class="two_kids"></span></span>
		</div>
	</div>
	
	<div id="three_points_main" class="droppable point_div">
		<div id="three_points_points">
			<?php if(!$chicken){ ?>
			<select id="three">
				<option value="">Size</option>
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3" style="color:green">3</option>
				<option value="4" style="color:red">4</option>
				<option value="5" style="color:green">5</option>
				<option value="8">8</option>
				<option value="13" style="color:green">13</option>
				<option value="16" style="color:red">16</option>
				<option value="20+" style="color:green">20+</option>
				<option value="32+" style="color:red">32+</option>
			</select> 
			<?php } ?>
			<span id="three_points_display">Size: <span class="three_size"></span></span>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<span id="three_points_div_count"><span class="three_kids"></span></span>
		</div>
	</div>
	
	<div id="five_points_main" class="droppable point_div">
		<div id="five_points_points">
			<?php if(!$chicken){ ?>
			<select id="five">
				<option value="">Size</option>
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3" style="color:green">3</option>
				<option value="4" style="color:red">4</option>
				<option value="5" style="color:green">5</option>
				<option value="8">8</option>
				<option value="13" style="color:green">13</option>
				<option value="16" style="color:red">16</option>
				<option value="20+" style="color:green">20+</option>
				<option value="32+" style="color:red">32+</option>
			</select> 
			<?php } ?>
			<span id="five_points_display">Size: <span class="five_size"></span></span>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<span id="five_points_div_count"><span class="five_kids"></span></span>
		</div>
	</div>
	
	<div id="eight_points_main" class="droppable point_div">
		<div id="eight_points_points">
			<?php if(!$chicken){ ?>
			<select id="eight">
				<option value="">Size</option>
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3" style="color:green">3</option>
				<option value="4" style="color:red">4</option>
				<option value="5" style="color:green">5</option>
				<option value="8">8</option>
				<option value="13" style="color:green">13</option>
				<option value="16" style="color:red">16</option>
				<option value="20+" style="color:green">20+</option>
				<option value="32+" style="color:red">32+</option>
			</select> 
			<?php } ?>
			<span id="eight_points_display">Size: <span class="eight_size"></span></span>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<span id="eight_points_div_count"><span class="eight_kids"></span></span>
		</div>
	</div>
	
	<div id="thirteen_points_main" class="droppable point_div">
		<div id="thirteen_points_points">
			<?php if(!$chicken){ ?>
			<select id="thirteen">
				<option value="">Size</option>
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3" style="color:green">3</option>
				<option value="4" style="color:red">4</option>
				<option value="5" style="color:green">5</option>
				<option value="8">8</option>
				<option value="13" style="color:green">13</option>
				<option value="16" style="color:red">16</option>
				<option value="20+" style="color:green">20+</option>
				<option value="32+" style="color:red">32+</option>
			</select> 
			<?php } ?>
			<span id="thirteen_points_display">Size: <span class="thirteen_size"></span></span>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<span id="thirteen_points_div_count"><span class="thirteen_kids"></span></span>
		</div>
	</div>
	
	<div id="trash" class="droppable"></div>
	<!--<div id="note_start" class="droppable"></div>-->
	<div id="note_start" class="droppable">
		<span id="start_div_count"><span class="start_kids"></span></span>
	</div>
	
	<div id="board"> </div>
	  
</div>

<script>
	points("#one", ".one_size");
	points("#two", ".two_size");
	points("#three", ".three_size");
	points("#five", ".five_size");
	points("#eight", ".eight_size");
	points("#thirteen", ".thirteen_size");
</script>

</body>
</html>
